#include "btn.h"

#include "dio.h"

static const int btn::cDebounce = 5;

void btn::btn(int ch) : _channel(ch), _debounce(cDebounce)
{
  _state=dio_read(_channel);
}


void btn::scan()
{
  if(_state == dio_read(_channel)){
    _debounce =0;
  }else{
   _debounce++;
    if(_debounce >4){
    	_state=dio_read(_channel);
    	_debounce =0;
    }
  }
 
}

int btn::state() const
{
  return _state;
}
